<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{      
    protected function _initAutoload(){
		$autoloader = new Zend_Application_Module_Autoloader(array(
			'namespace' => '',
            'basePath' => APPLICATION_PATH,
		));
		return $autoloader;
	}

	
	
	    protected function _initSetConstants(){
        $config = parse_ini_file(APPLICATION_PATH . '/configs/constant.ini');
        foreach ($config as $key => $value){
            if(!defined($key)){
                define($key, $value);
            }
    }
    }
	
	protected function _initDb() {
		$dbOption = $this->getOption('resources');
    	$dbOption = $dbOption['db'];
        // Setup database
        $db = Zend_Db::factory($dbOption['adapter'],$dbOption['params']);
        $db->setFetchMode(Zend_Db::FETCH_ASSOC);
        $db->query("SET NAMES 'utf8'");
        $db->query("SET CHARACTER SET 'utf8'");       
       
        Zend_Registry::set('connectDB',$db);
                
        //Khi thiet lap che do nay model moi co the su dung duoc
        Zend_Db_Table::setDefaultAdapter($db);
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        // Return it, so that it can be stored by the bootstrap
        return $db;
	}
	
	protected function _initMail() {
		$mailOption = $this->getOption('resources');
		$mailOption = $mailOption['mail'];
		$host = $mailOption['host'];
		$mailOption = $mailOption['info'];
    	
    	$transport = new Zend_Mail_Transport_Smtp($host, $mailOption);
    	Zend_Registry::set('mailTransport',$transport);
    	Zend_Mail::setDefaultTransport ( $transport );
        
        /*
        * Cau hinh cho link than thien
        */
       // $front = Zend_Controller_Front::getInstance();       
       // $front->addModuleDirectory(APPLICATION_PATH . "/modules");
//        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routers.ini', 'thietlap');
//        $router = new Zend_Controller_Router_Rewrite();
//        
//        $router = $router->addConfig($config, 'routes');
//        $front->setRouter($router);    
//        
//         
//        return $front;
//        
        
	}
	
  
    
 
}

